{include file="common/header"/}
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-row">
                        <form action="" class="layui-form">
                        <div class="layui-row layui-col-space10">
                            <div class="layui-col-md2 layui-col-xs4">
                            <select name="mime" id="mime">
                                <option value="">全部</option>
                              {volist name="mimelist" id="vo"}
                                <option value="{$vo.mime}">{$vo.mimename}</option>
                              {/volist}
                            </select> 
                          </div>
                          <div class="layui-col-md2 layui-col-xs4">
                            <input type="text" id='keys' name="keys" placeholder="{:lang('pleaseEnter')}" autocomplete="off" class="layui-input">
                          </div>
                          <div class="layui-col-md2 layui-col-xs4">
                            <input type="button" id="searchBtn" name="submit" class="layui-btn" value="搜索">
                          </div>
                        </div>
                      </form>
                    </div>
                    <div class="layui-row">
                        <table class="layui-table" id="list" lay-filter="toolbar"></table>
                    </div>
                </div>
            

            </div>
        </div>
    </div>
</div>

<script type="text/html" id="action">
    <a  class="layui-btn layui-btn-danger layui-btn-xs"  lay-event="selectAttach">选择</a>
</script>
<script type="text/html" id="status">
    <input type="checkbox" name="status" data-href="{:url('state')}" value="{{d.id}}" lay-skin="switch" lay-text="开启|关闭" lay-filter="status" {{ d.status == 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="create_time">
    {{layui.util.toDateString(d.create_time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>

<script type="text/html" id="path">
    <a href="{{d.path}}" target="_blank"><img src="{{d.path}}" width="50" ></a>
</script>

{include file="common/footer"/}
<script>
var table;
var searchObj = {};
layui.use(['table'], function () {
    var $ = layui.jquery,
        table = layui.table;

    table.render({
        elem: '#list',
        url: '{:url("index")}',
        method: 'post',
        title: '附件数据表',
        id:'list',
        cols: [[
            {field: 'name', title: '文件名', width: 120,},
            {field: 'mime', title: '文件类型', width: 100},
            {field: 'path', title: '路径', minWidth: 120,  templet:'#path'},
            {title:'操作',width:150, toolbar: '#action',align:"center"},

        ]],
        limits: [10, 15, 20, 25, 50, 100],
        limit: 15,
        page: true
    });
    // 搜索
    $('#searchBtn').click(function(){
        searchObj['mime'] = $('#mime').find('option:selected').val();
        searchObj['keys'] = $('#keys').val();
        table.reload('list',{where:searchObj});
    });
    table.on('tool(toolbar)', function(obj){
        var data = obj.data;
        if(obj.event === 'selectAttach'){
            $(".attach", window.parent.document).val(data.path);
            $(".layui-upload-img", window.parent.document).attr('src',data.path);
            index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index)
        }

    });
});

</script>